#ifndef ELCOMPONENT_H
#define ELCOMPONENT_H

#include <QWidget>
#include "elpalette.h"

class ElTooltip;

class ElComponent : public QWidget
{
    Q_OBJECT
    Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged)
    Q_PROPERTY(int x READ x WRITE setX)
    Q_PROPERTY(int y READ y WRITE setY)
public:
    ElComponent(QWidget *parent = nullptr);

    void setX(int x);
    void setY(int y);

    void setPalette(const ElPalette &palette);
    ElPalette palette() const;

    void setOpacity(qreal opacity);
    qreal opacity() const;

    ElTooltip *tooltip() const;
    void setTooltip(ElTooltip *tooltip);

protected:
    qreal _opacity = 1;
    ElPalette _palette;
    ElTooltip *_tooltip = nullptr;

    // global painter setting
    void initPainter(QPainter *painter) const;
    QRectF getDrawRect() const;
    // initPalette() must be called after _theme being initialized.
    virtual void initPalette() = 0;

    void showTooltip();
    void hideTooltip();

signals:
    void opacityChanged(qreal opacity);
};

#endif // ELCOMPONENT_H
